<template>
  <div class="page-style">
    <el-row>
      <el-col :span="7">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="是否显示">
            <el-switch v-model="val" @change="switchChange" />
          </el-form-item>
          <el-form-item label="AppId">
            <el-input v-model="form.appid" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">提交</el-button>
            <!-- <el-button>取消</el-button> -->
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import { operationAppContactApi } from '@/api/foregrounding'
import { getBrandAdApi } from '@/api/brand'
export default {
  data() {
    return {
      form: {
        id: this.$store.state.user.brand_id,
        shopping_status: 0,
        appid: ''
      },
      val: false
    }
  },
  created() {
    this.getbrandFun()
  },
  methods: {
    switchChange(val) {
      console.log(val, this.val)
      if (val) {
        this.form.shopping_status = '1'
      } else if (!val) {
        this.form.shopping_status = '0'
      }
    },
    getbrandFun() {
      const data = {
        id: this.$store.state.user.brand_id
      }
      getBrandAdApi(data).then(res => {
        this.form.appid = res.appid
        this.form.shopping_status = res.status
        if (res.shopping_status !== '0') {
          this.val = true
        } else {
          this.val = false
        }
      })
    },
    onSubmit() {
      console.log('submit!')
      const data = this.form
      console.log(this.form)
      operationAppContactApi(data).then(res => {
        if (res.code === 200) {
          this.$message.success('信息提交成功！')
        }
      })
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
